package com.hq.fxh.No3_TuiGuang.MyMoBan.Activity.item;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.hq.fxh.No3_TuiGuang.MyMoBan.Activity.AdBannerInfo;
import com.hq.fxh.R;
import com.hq.fxh.Utils.GlideUtils;


/**
 * @author 大圣
 * @ClassName BannerAdContentItem
 * @Description : banner广告
 * @Created 2015/12/22 0022
 * @Email qwqe601660957@163.com
 */
public class BannerAdContentItem extends LinearLayout {
    private ImageView ivBannerPic;
    private RelativeLayout headfill;
    private ViewGroup.LayoutParams params;

    //    private AppCompatCheckBox cbPic;
    public BannerAdContentItem(Context context) {
        super(context);
        inflate(context, R.layout.item_banner_ad_content, this);
        initView();
    }

    private void initView() {
        ivBannerPic = (ImageView) findViewById(R.id.ivBannerPic);
//        cbPic = (AppCompatCheckBox) findViewById(R.id.cbPic);
        headfill = (RelativeLayout) findViewById(R.id.Headfill);

//        params = headfill.getLayoutParams();
//        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
//        int width = wm.getDefaultDisplay().getWidth();
//        params.height = width*250/750;
    }

    /**
     *
     * @param adInfo
     */
    public void showAdInfo(final AdBannerInfo adInfo){
        if(adInfo != null){

            final AdBannerInfo.AdvertDetailBean merchantArticleBannerModel = adInfo.getAdvert_detail();
            if(merchantArticleBannerModel != null){

                final String bannerPic = merchantArticleBannerModel.getPic();
                if(bannerPic != null){
//                    if(bannerPic.isNative()){
                        headfill.setVisibility(VISIBLE);
                        ivBannerPic.setVisibility(VISIBLE);
//                        Bitmap bitmap = ImageUtils.bytes2Bimap(Base64.decode(bannerPic.getPicData(), Base64.DEFAULT));
//                        ivBannerPic.setImageBitmap(bitmap);
                 //   ImageLoader.getInstance().load(getContext(),ivBannerPic,bannerPic);
                    GlideUtils.loadImageView(getContext(),bannerPic,ivBannerPic);

                }else{
                        headfill.setVisibility(VISIBLE);
                        ivBannerPic.setVisibility(VISIBLE);
                 //       ImageLoader.getInstance().load(getContext(),ivBannerPic,bannerPic);
                    GlideUtils.loadImageView(getContext(),bannerPic,ivBannerPic);

                }
                }
//                if(adInfo.isFirst()){
////                    cbPic.setVisibility(View.GONE);
//                    ivBannerPic.setVisibility(GONE);
//                    headfill.setVisibility(VISIBLE);
//                }else{
////                    cbPic.setVisibility(View.VISIBLE);
//                }
            }
//            cbPic.setChecked(adInfo.isSelect());
//            cbPic.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//                @Override
//                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                    adInfo.setIsSelect(isChecked);
//                }
//            });
        }
}
